package com.example.sjly.ui.scheduling.room;


import android.content.Context;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;
//选择界面

@Database(entities ={TOrderMess.class, TOrderIn.class},version =2,exportSchema = false)
public abstract class TOrderRoomDatabase extends RoomDatabase{

    private static TOrderRoomDatabase instance;

    public abstract TOrderDAO torderDAO();
    public abstract TOrderInDAO torderinDAO();

    public static TOrderRoomDatabase getInstance(Context context){
        if(instance == null){
            instance = Room.databaseBuilder(context.getApplicationContext(),TOrderRoomDatabase.class,"TOrder.db")
                    //需修改，因为可能会卡
                    .fallbackToDestructiveMigration()//数据库更新时删除数据重新创建
                    .addMigrations(MIGRATION_1_2)
                    .allowMainThreadQueries()
                    .build();
        }
        return instance;

    }


         static final Migration MIGRATION_1_2 = new Migration(1,2) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
        //将数据表device创建出来
        database.execSQL("CREATE TABLE 'TOrderMessageIn' ('id' Long NOT NULL,'TeacherName' String,'UserName' String,'AddressMess' String," +
        "'TeacherPhone' String,'TeacherEmali' String,PRIMARY KEY ('id')) ");
        database.execSQL("CREATE TABLE 'TOrderMessage'('id'  Long NOT NULL,'CourseType' String,'ConstructionType' String,'VersionType' String," +
                "'UserName' String,'Tryteach' int,'ChoiceCalendarYear' int,'ChoiceCalendarMonth' int,'ChoiceCalendarDay' int,PRIMARY KEY ('id'))");
        }
        };


}